package tree.treerecursion;

import tree.TreeNode;

/**
 * @Classname : SymmetricTree
 * @Description :
 * <a href="https://leetcode.cn/problems/symmetric-tree/">101. 对称二叉树</a>
 * @Author : chentianyu
 * @Date 2023/1/4 21:27
 */


public class SymmetricTree {
    public boolean isSymmetric(TreeNode root) {
        return isSymmetric(root, root);
    }

    private boolean isSymmetric(TreeNode left, TreeNode right) {
        if (left == null && right == null) return true;
        if (left == null || right == null) return false;
        if (left.val != right.val) return false;

        return isSymmetric(left.left, right.right) && isSymmetric(left.right, right.left);
    }
}
